package com.whfc.emp.service.impl;

import com.whfc.emp.dao.ApprovalRecordMapper;
import com.whfc.emp.entity.ApprovalRecord;
import com.whfc.emp.service.ApprovalRecordService;
import com.whfc.entity.dto.Apply.rep.EntryAuditRep;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;

import java.util.Collections;
import java.util.List;

@DubboService(interfaceClass = ApprovalRecordService.class, version = "1.0.0", timeout = 50000)
public class ApprovalRecordServiceImpl implements ApprovalRecordService {
    @Autowired
    private ApprovalRecordMapper approvalRecordMapper;

    @Override
    public int insertApprovalRecord(ApprovalRecord approvalRecord) {
        return approvalRecordMapper.insertApprovalRecord(approvalRecord);
    }

    @Override
    public ApprovalRecord getApprovalRecordById(Integer id) {
        return approvalRecordMapper.getApprovalRecordById(id);
    }

    @Override
    public ApprovalRecord getByApplicationIdAndApproverId(Integer applicationId, Integer approverId) {
        ApprovalRecord approvalRecord = approvalRecordMapper.getByApplicationIdAndApproverId(applicationId,
                approverId);
        return approvalRecord;
    }

    @Override
    public int updateApprovalRecord(ApprovalRecord approvalRecord) {
        return approvalRecordMapper.updateApprovalRecord(approvalRecord);
    }

    @Override
    public int deleteApprovalRecordById(Integer id) {
        return approvalRecordMapper.deleteApprovalRecordById(id);
    }

    @Override
    public List<EntryAuditRep> entryReview(List<Integer> pidList, Integer userId) {
        return approvalRecordMapper.entryReview(pidList, userId);
    }

    @Override
    public List<ApprovalRecord> getParentNode(Integer approverType, Integer applicationId) {
        return approvalRecordMapper.getParentNode(approverType, applicationId);
    }

    @Override
    public List<ApprovalRecord> selectRecordByApplyIdAndAuditType(Integer applicationId, Integer reviewType) {
        List<ApprovalRecord> approvalRecords = approvalRecordMapper.selectRecordByApplyIdAndAuditType(applicationId,
                reviewType);
        if (!CollectionUtils.isEmpty(approvalRecords)) {
            return approvalRecords;
        }
        return Collections.emptyList();
    }


    @Override
    public List<ApprovalRecord> selectByApproverId(Integer approverId) {
        return approvalRecordMapper.selectByApproverId(approverId);
    }

}